package com.cursino.wilson.game.baccarat;

/**
 * Define baccarat rules.
 * @author <a href="mailto:"wilson.cursino@gmail.com"> Wilson Soethe Cursino </a>
 * @since 1.0
 */
public class BaccaratRules {

    /**
     * Returns true if the player must get another card.
     * @param bankerValue
     *            the banker value
     * @param playerValue
     *            the player value
     * @return true, if needs another card.
     */
    public static boolean doesPlayerGetsAnotherCard(int bankerValue, int playerValue) {
        // If either the Player or the Banker has a total of an 8 or a 9 after the first four cards are dealt, they both stand. This rule overrides all other
        // rules (but does not apply once a fifth card is dealt).
        if (bankerValue >= 8 || playerValue >= 8) {
            return false;
        }

        // If the Player total is 5 or less, then the Player hits, otherwise the Player stands.
        if (playerValue <= 5) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Returns true if the banker must get another card
     * @param bankerValue
     *            the banker's hand value (of first 2 cards)
     * @param playerValue
     *            the player's hand value (of first 2 cards)
     * @param playerThirdCardValue
     *            the player's third card value (if player has not got a third card, this value will not be used and can thus be set to any integer).
     */
    public static boolean doesBankerGetsAnotherCard(int bankerValue, int playerValue, int playerThirdCardValue) {
        if (bankerValue >= 8 || playerValue >= 8) {
            return false;
        }
        if (bankerValue == 7) {
            return false;
        }

        // case if the player has not got a third card
        if (playerValue >= 6) {
            if (bankerValue == 6) {
                return false;
            } else {
                return true;
            }
        }
        // case if the player has got a third card; implement the third-card rule
        switch (bankerValue) {
        case 0:
        case 1:
        case 2:
            return true;
        case 3:
            if (playerThirdCardValue != 8)
                return true;
            break;
        case 4:
            if (playerThirdCardValue >= 2 && playerThirdCardValue <= 7)
                return true;
            break;
        case 5:
            if (playerThirdCardValue >= 4 && playerThirdCardValue <= 7)
                return true;
            break;
        case 6:
            if (playerThirdCardValue == 6 || playerThirdCardValue == 7)
                return true;
            break;
        }
        return false;
    }
}